let moneyNum:number[] = [1000000,1000,1]
let moneyText:string[] = ['m','k','']
export default class StringHelper {


    static replace(str:string,key:number | string,value:any):string{
        str = str.replace("%{"+key+"}", value);
        return str;
    }

    /**
     * 获取最后一个字符串
     * @param str 
     * @param tag 
     */
    static laststring(str: string,tag:string){
        let index: number = str.indexOf(tag);
        if(index >= 0){
            let list = str.split(tag);
            return list[list.length - 1]
        }
        return str;
    }

    /**
     * 
     * @param num 
     */
    static getShortStr(num:number):string{
        let i = moneyNum.length - 1;
        let money = 0;
        for (let index = 0; index < moneyNum.length; index++) {
            const element = moneyNum[index];
            if(num >= element){
                i = index
                money = Math.floor(num * 10/ element);
                break;
            }
            
        }
        let tail = moneyText[i];
        return (money / 10) + tail;
    }
}
